//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ysy.tz.core.selfcomp;

import com.ysy.tz.core.engine.ApplicationContext;
import com.ysy.tz.core.engine.CustomerFXMLLoader;
import com.ysy.tz.core.engine.ParameterInitializable;
import com.ysy.tz.core.excel.ExcelOutHandler;
import com.ysy.tz.core.utils.FileResourceLoader;
import java.io.IOException;
import java.io.InputStream;
import java.util.ResourceBundle;
import javafx.scene.control.Button;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import org.controlsfx.control.MaskerPane;

public class MainPage extends StackPane {
    private Region topBanner;
    private Region centerPage;
    private Region oldPane;
    private VBox containerBox = new VBox();
    private MaskerPane maskerPane = new MaskerPane();
    private MaskerPane excelPane;
    private Object oldController;

    public MainPage() {
        this.maskerPane.setVisible(false);
        this.excelPane = new MaskerPane();
        this.excelPane.setVisible(false);
        VBox vBox = new VBox();
        ProgressIndicator node = new ProgressIndicator();
        node.progressProperty().bind(this.excelPane.progressProperty());
        vBox.getChildren().add(node);
        Button excelCancelbtn = new Button(ApplicationContext.commonBundle.getString("common_cancel"));
        excelCancelbtn.setOnMousePressed((mouseEvent) -> {
            this.excelPane.setProgress(0.0);
            this.excelPane.setVisible(false);
            ExcelOutHandler.singleWorkerThread.stop();
            ExcelOutHandler.singleWorkerThread = null;
        });
        vBox.getChildren().add(excelCancelbtn);
        this.excelPane.setProgress(0.1);
        this.excelPane.setProgressNode(vBox);
        this.excelPane.setText(ApplicationContext.commonBundle.getString("operating_Excel"));
        this.prefWidthProperty().bind(ApplicationContext.mainStage.widthProperty());
        this.getChildren().add(this.containerBox);
        this.getChildren().add(this.maskerPane);
        this.getChildren().add(this.excelPane);
    }

    public void redirectCenterPage() {
        this.loadCenterPage(this.centerPage, (Object)null);
    }

    public void loadCenterPage(String funcName) throws IOException {
        CustomerFXMLLoader customerFXMLLoader = new CustomerFXMLLoader();
        customerFXMLLoader.setResources(ResourceBundle.getBundle("views/i18n/" + funcName));
        InputStream inputStream = FileResourceLoader.loadInputStream("/views/" + funcName + "View.fxml");
        Region centPane = (Region)customerFXMLLoader.load(inputStream);
        Object controller = customerFXMLLoader.getController();
        this.loadCenterPage(centPane, controller);
        inputStream.close();
    }

    private void loadCenterPage(Region node, Object controller) {
        if (controller != null) {
            ApplicationContext.eventBus.register(controller);
        }

        if (this.oldController != null) {
            try {
                ApplicationContext.eventBus.unregister(this.oldController);
            } catch (Exception var4) {
            }

            if (this.oldController instanceof ParameterInitializable) {
                ParameterInitializable parameterInitializable = (ParameterInitializable)this.oldController;
                parameterInitializable.unload();
            }
        }

        this.oldController = controller;
        node.prefHeightProperty().bind(this.heightProperty().subtract(this.topBanner.prefHeightProperty()));
        node.prefWidthProperty().bind(this.widthProperty());
        if (this.oldPane != null) {
            this.containerBox.getChildren().remove(this.oldPane);
        }

        this.containerBox.getChildren().add(node);
        this.oldPane = node;
    }

    public Region getTopBanner() {
        return this.topBanner;
    }

    public void setTopBanner(Region topBanner) {
        this.containerBox.getChildren().remove(this.topBanner);
        this.topBanner = topBanner;
        this.containerBox.getChildren().add(this.topBanner);
    }

    public void setCenterPage(Region centerPage) {
        this.centerPage = centerPage;
    }

    public MaskerPane getMaskerPane() {
        return this.maskerPane;
    }

    public MaskerPane getExcelPane() {
        return this.excelPane;
    }
}
